Author

Diego Cruz Aguilar

Published

July 1, 2023

title: Experimentos Tesis author: Diego Cruz Aguilar date: 2023-07-01 toc: true number-sections: true execute: echo: true cache: true format: html: code-fold: true code-tools: true jupyter: python3



title: Experimentos Tesis author: Diego Cruz Aguilar date: 2023-07-01 toc: true number-sections: true execute: echo: true cache: true format: html: code-fold: true code-tools: true jupyter: python3


1 Librerías

Code
import time
import numpy as np
import pandas as pd
from plotly.subplots import make_subplots
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.graph_objects as go
from itables import show
from utils.mimic_load import load_csv, segment_signal_by_label

2 Variables globales

Code
RANDOM_SEED = int(time.time())
USER_SELECT = 1
SEGMENT_SIZE = 3750  # Equivalente a 30s de muestras
FS = 1250
FOLDER_PATH = "./dataset/mimic_perform_af_csv"

3 Carga de datos

Code
final_df = load_csv(FOLDER_PATH, USER_SELECT)
filtered_df = final_df[final_df['label'] == 0]

4 Conocer los datos

4.1 Ver los primeros datos y sus cabeceras

Code
final_df.head()
Time PPG ECG resp numb_user label
0 0.000 0.537634 0.425781 -0.029340 1 0
1 0.008 0.534702 0.404297 -0.036675 1 0
2 0.016 0.531769 0.400391 -0.044010 1 0
3 0.024 0.528837 0.400391 -0.053790 1 0
4 0.032 0.524927 0.419922 -0.061125 1 0

4.2 Informacion de los datos

Code
final_df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2100014 entries, 0 to 2100013
Data columns (total 6 columns):
 #   Column     Dtype  
---  ------     -----  
 0   Time       float64
 1   PPG        float64
 2   ECG        float64
 3   resp       float64
 4   numb_user  int64  
 5   label      int64  
dtypes: float64(4), int64(2)
memory usage: 96.1 MB

4.3 Descripcion de los datos

Code
final_df.describe()
Time PPG ECG resp numb_user label
count 2.100014e+06 2.100014e+06 2.100014e+06 2.100014e+06 2.100014e+06 2.100014e+06
mean 6.000000e+02 1.193070e+00 3.920216e-01 2.226942e-01 1.057143e+01 9.285714e-01
std 3.464126e+02 7.767317e-01 2.349270e-01 4.319208e-01 5.827452e+00 2.575394e-01
min 0.000000e+00 0.000000e+00 -5.019608e-01 -1.846506e+00 1.000000e+00 0.000000e+00
25% 3.000000e+02 4.633431e-01 2.346041e-01 -4.156479e-02 6.000000e+00 1.000000e+00
50% 6.000000e+02 8.064516e-01 3.847656e-01 2.200000e-01 1.150000e+01 1.000000e+00
75% 9.000000e+02 1.893451e+00 5.195312e-01 4.643077e-01 1.600000e+01 1.000000e+00
max 1.200000e+03 4.001955e+00 1.503922e+00 2.844215e+00 1.900000e+01 1.000000e+00

4.4 Tamaño de los datos

Code
final_df.shape
(2100014, 6)

4.5 Vusualizar su distribución

Code
# Histogramas de las variables
filtered_df[['PPG', 'ECG', 'resp']].hist(bins=50, figsize=(10, 8))
plt.suptitle("Distribuciones de las Variables")
plt.show()

4.6 Detección de valores atípicos

Code
# Visualización de boxplots para detectar valores atípicos
filtered_df[['PPG', 'ECG', 'resp']].plot(kind='box', subplots=True, layout=(1, 3), figsize=(12, 6))
plt.suptitle("Boxplots para Identificación de Valores Atípicos")
plt.show()

4.7 Analisis de correlacion

Code
# Matriz de correlación
correlation_matrix = filtered_df.corr()

sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm')
plt.title("Matriz de Correlación")
plt.show()

4.8 Analisi de frequencias

Code
# Transformada de Fourier en PPG
ppg_freq = np.fft.fft(filtered_df['PPG'].values)
frequencies = np.fft.fftfreq(len(ppg_freq), d=0.008)  # 0.008 s entre cada medida

# Gráfica de frecuencias
plt.figure(figsize=(12, 6))
plt.plot(frequencies[:len(frequencies)//2], np.abs(ppg_freq)[:len(ppg_freq)//2])
plt.title("Análisis de Frecuencia de PPG")
plt.xlabel("Frecuencia (Hz)")
plt.ylabel("Amplitud")
plt.show()

4.9 Reconstruir la señal

Code
fig = make_subplots(rows=2, cols=1, shared_xaxes=True,
                    subplot_titles=("PPG Signal", "Respiration Signal"),
                    vertical_spacing=0.1)

# Agregar la señal PPG
fig.add_trace(go.Scatter(x=filtered_df["Time"], y=filtered_df["PPG"], mode="lines", name="PPG"), row=1, col=1)

# Agregar la señal de respiración
fig.add_trace(go.Scatter(x=filtered_df["Time"], y=filtered_df["resp"], mode="lines", name="Resp"), row=2, col=1)

# Actualizar el layout
fig.update_layout(height=600, width=800, title_text="Señales PPG y Respiración", showlegend=False)
fig.update_xaxes(title_text="Time (s)", row=2, col=1)
fig.update_yaxes(title_text="PPG", row=1, col=1)
fig.update_yaxes(title_text="Resp", row=2, col=1)

# Mostrar gráfico
fig.show()
Figure 1: Reconstruccion de la señal de uno de los usuarios

5 Experimentos

5.1 Segmentar los datos

Code
segments_ppg, segments_resp, segment_labels, user_ids = segment_signal_by_label(
    final_df, SEGMENT_SIZE
)

middle_segment = len(segments_ppg) // 2
segments_ppg[middle_segment], segments_resp[middle_segment]
(array([2.15249267, 2.22091887, 2.285435  , ..., 1.94330401, 2.08797654,
        2.22385142]),
 array([-0.02626756, -0.02565669, -0.02504582, ..., -0.06108735,
        -0.06047648, -0.05986561]))

5.2 Obtener la fingerprint de la union de las señales(PPG y respiración)

Code
from utils.extact_features import compute_features_parallel
combined_features = compute_features_parallel(segments_ppg, segments_resp, FS)
combined_features[0], len(combined_features)
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3596: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/_methods.py:138: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3596: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/_methods.py:138: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3596: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/_methods.py:138: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3596: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/_methods.py:138: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3596: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/_methods.py:138: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3596: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/_methods.py:138: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3596: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/_methods.py:138: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3596: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/numpy/_core/_methods.py:138: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
(array([ 1.36472759e+00,  2.70545818e-01, -9.22594233e-01,  1.25886370e-01,
         1.98144061e+00,  8.24251787e-01,  9.17510633e+02,  6.14145276e+00,
        -1.80968071e-04,  8.35478571e-03,  9.32966678e-01,  6.03824831e-01,
         2.91382149e-02, -2.04860227e-02,  3.31018818e-02,  5.75799279e+00,
        -7.45894319e-06,  1.42086863e-03,  1.42183565e+01,  6.53088052e-01,
         1.40151520e-02, -8.57327975e-03,  1.90182574e-03,  6.43393434e+00,
        -6.37711225e-06,  3.73592271e-04,  1.74541833e+00, -2.17755297e-01,
         1.66478462e-03, -2.55753171e-03,  2.62191060e-04,  7.24331034e+00,
         6.19581879e-02,  7.24997586e-01, -4.86277977e-01,  9.34663499e-01,
         1.90172755e+00, -9.71714161e-01,  2.54670412e+02,  5.96627214e+00,
        -9.52988670e-05,  4.39476325e-03,  1.85439603e+01,  1.20304746e-01,
         3.27447597e-02, -3.27447597e-02,  9.29437547e-03,  5.61846673e+00,
        -8.06641631e-05,  1.23739345e-03,  5.59740223e-01, -4.65897730e-02,
         5.74069967e-03, -5.74069967e-03,  1.45769151e-03,  6.54296586e+00,
         8.63515085e-05,  5.93021050e-04, -5.57631423e-01,  1.88280548e-02,
         1.72886744e-03, -1.72886744e-03,  6.75883693e-04,  7.10000314e+00,
         4.96853702e-01,  2.83236494e-01, -1.12771811e+00, -3.25932656e-04,
         8.32995690e-01,  4.51104214e-01,  6.14738564e-01,  9.89010989e+02,
         3.40136054e+02]),
 560)

5.3 Seleccionar clasificadores

Code
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression

# from sklearn.ensemble import GradientBoostingClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier

classifiers = {
    "Random Forest": RandomForestClassifier(n_estimators=100, random_state=RANDOM_SEED),
    "Logistic Regression": LogisticRegression(max_iter=1000, random_state=RANDOM_SEED),
    "KNN": KNeighborsClassifier(),
    "SVM": SVC(random_state=RANDOM_SEED),
    "Decision Tree": DecisionTreeClassifier(),
    "Naive Bayes Gaussiano": GaussianNB(),
}

5.4 Probar clasificadores

Code
from utils.ml import (
    MakeExperiment,
    calculate_metrics_binary,
    calculate_metrics_multiclass,
    train_test_split_grouped,
)

X = np.array(combined_features)
y = np.array(user_ids)

make_experiment = MakeExperiment(
    X, y, user_ids, classifiers, calculate_metrics_multiclass, RANDOM_SEED
)

# y = np.array(segment_labels)

# make_experiment = MakeExperiment(
#    X, y, user_ids, classifiers, calculate_metrics_binary, RANDOM_SEED
# )

#split_fn = lambda X, y, test_size, random_state: train_test_split_grouped(
#    X, y, user_ids, test_size, random_state
#)

# results = make_experiment.simple_test(n_test=1)
# results = make_experiment.k_fold_cross_validation()
results = make_experiment.repeated_group_k_fold_cross_validation()
# results = make_experiment.leave_one_out_cross_validation()
# results = make_experiment.leave_one_group_out_cross_validation()
# results = make_experiment.monte_carlo_cross_validation()
# results = make_experiment.stratified_k_fold_cross_validation()

Probando clasificador: Random Forest
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/model_selection/_split.py:91: UserWarning:

The groups parameter is ignored by RepeatedKFold

/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/model_selection/_split.py:91: UserWarning:

The groups parameter is ignored by KFold

/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))

Probando clasificador: Logistic Regression
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))

Probando clasificador: KNN

Probando clasificador: SVM
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))

Probando clasificador: Decision Tree
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))

Probando clasificador: Naive Bayes Gaussiano
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
/home/think-crag/.cache/pypoetry/virtualenvs/experimentos-NZxwsTu5-py3.12/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1531: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))

6 Resultados

Code
df_results = pd.DataFrame(results)
df_results.to_csv("One-to-Many-Results.csv", index=False)
df_ordenado = df_results.sort_values(by='accuracy', ascending=False)
show(df_ordenado)
accuracy precision f1 fpr_weighted fnr_weighted recall_weighted grr model
Loading ITables v2.2.3 from the internet... (need help?)

6.1 Gráfico de líneas de precisión de los clasificadores

Code
# Crear gráfico de líneas
fig = go.Figure()
unique_models = df_results['model'].unique()
# Trazar los datos para cada clasificador
for name in unique_models:
    # Filtrar los datos para el clasificador actual
    model_data = df_results[df_results['model'] == name]

    # Agregar el trazo
    fig.add_trace(
        go.Scatter(
            x=model_data.index + 1,  # Índices ajustados como número de prueba
            y=model_data['accuracy'],  # Precisión
            mode="lines+markers",  # Mostrar líneas y puntos
            name=name,  # Nombre del clasificador
        )
    )

# Configuración del diseño
fig.update_layout(
    title="Comparación de Accuracy entre Clasificadores",
    xaxis_title="Número de Prueba",
    yaxis_title="Accuracy",
    template="plotly_white",
)

# Mostrar gráfico
fig.show()

6.2 Comparacion con el estado del arte

Code
mejor_modelo = df_results.loc[df_results['accuracy'].idxmax()]
models_accuracies = {
    "Pu et al": .9894,
    "Zhao et al static": .96,
    "Zhao et al mivement": .9073,
    "Aly et al": .935,
    "Wu et al": .921,
    "Zhang": .949,
    f"Proposed ({mejor_modelo['model']})": mejor_modelo['accuracy'],
}

# Prepare data
models = list(models_accuracies.keys())
accuracies = list(models_accuracies.values())

# Create the scatter plot
fig = go.Figure(data=[
    go.Scatter(
        x=models,
        y=accuracies,
        mode='markers+lines',
        marker=dict(size=10, color=accuracies, colorscale='Viridis', showscale=True),
        line=dict(dash='solid'),
        name='Accuracy'
    )
])

# Customize layout
fig.update_layout(
    title="Model Accuracies",
    xaxis_title="Models",
    yaxis_title="Accuracy",
    yaxis=dict(range=[0.9, 1.0]),
    template="plotly_white"
)

# Display the chart
fig.show()